<?php 

require "../gobal.php";


function gridOrderSum(){

    $page=(int)$_REQUEST["page"];
    $limit=(int)$_REQUEST["rows"];
    
    $start=($page-1)*$limit;

    $where="";
    
    $mode=$_GET["mode"];

    $where="where oper_state!='cancel'";
    
    if($mode=="3M"){
        
        $where.=" and created_at between date_sub(now(),interval 3 month) and now()";
        
    }
    
	$sql="select * from order_sum_detail  $where order by created_at desc  limit $start,$limit";
    $rows=fetch_rows($sql);
    
    $rows_count=sizeof($rows);
    $total=$rows_count;
    if($page>1||$rows_count>=$limit){
        $sql2="select count(*) as c from order_sum_detail $where ";
        $rr=fetch_rows($sql2);
        $total=$rr[0]["c"];
    }
    
    
    $grid = array('total' => $total,'rows'=>$rows);
	echo_json($grid);
	
}


function doCancelOrder(){
    
    $oids=trim($_REQUEST["oids"],",");
    
    $sql=" order_sum set oper_state='cancel',oper_at=NOW() where id in ($oids)";
    
    $eff=update_row($sql);
    
    //$sql= " INTO `order_oper_log`(`id`, `order_sum_id`, `admin_id`, `create_at`, `oper_code`, `oper_remark`)  ";
    $msg="作废成功";
    $re=array("eff"=>$eff,"msg"=>$msg);
    
    echo_json($re);
    
}


 

$action=$_GET["action"] ;



switch($action){

	case "gridOrderSum":  gridOrderSum();break;
	case "doCancelOrder":  doCancelOrder();break;
	default : break;

}



?>